//
//  BetBaseCollectionVC.m
//

/*
 
 //列间距
 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
 return 0.5f;
 }
 
 //配置item大小
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
 }
 
 //行间距
 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
 return 0.5f;
 }
 
 //section边距
 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
 return UIEdgeInsetsMake(15, 0, 15, 0);
 }
 
 //Footer 高度
 -(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
 
 }
 
 //Header 高度
 -(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
 
 }
 
 //头部底部视图
 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
 if([kind isEqualToString:UICollectionElementKindSectionFooter]){
 FooterView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
 
 return view;
 }else if([kind isEqualToString:UICollectionElementKindSectionHeader]){
 HeaderView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head" forIndexPath:indexPath];
 return view;
 }
 return nil;
 }
 
 */

#import "BaseCollectionVC.h"

@interface BaseCollectionVC ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation BaseCollectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)registerCell:(NSString*)identifier{
    [self.collectionView registerNib:[UINib nibWithNibName:identifier bundle:nil] forCellWithReuseIdentifier:identifier];
}
-(void)registerHeader:(NSString*)identifier{
    [self.collectionView registerNib:[UINib nibWithNibName:identifier bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:identifier];
}

-(void)registerFooter:(NSString*)identifier{
    [self.collectionView registerNib:[UINib nibWithNibName:identifier bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:identifier];
}

-(UICollectionView *)collectionView{
    if(_collectionView==nil){
        UICollectionViewFlowLayout *layouut = [[UICollectionViewFlowLayout alloc]init];
        layouut.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero  collectionViewLayout:layouut];
        layouut.minimumLineSpacing = 0.f;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        layouut.minimumInteritemSpacing = 0.f;
        _collectionView.backgroundColor = [UIColor clearColor];
    }
    return _collectionView;
}


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    if([self.delegate respondsToSelector:@selector(numberSections)]){
        return [self.delegate numberSections];
    }
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if([self.delegate respondsToSelector:@selector(numberOfSections:)]){
        return [self.delegate numberOfSections:section];
    }
    return 0;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if([self.delegate respondsToSelector:@selector(cell:indexPath:)]){
        return [self.delegate cell:collectionView indexPath:indexPath];
    }
    return nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if([self.delegate respondsToSelector:@selector(itemSize:)]){
        return [self.delegate itemSize:indexPath];
    }
    return CGSizeZero;
}

//列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    if([self.delegate respondsToSelector:@selector(columnSpacing:)]){
        return [self.delegate columnSpacing:section];
    }
    return 0.f;
}


//行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    if([self.delegate respondsToSelector:@selector(lineSpacing:)]){
        return [self.delegate lineSpacing:section];
    }
    return 0.f;
}

//section边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    if([self.delegate respondsToSelector:@selector(sectionMargin:)]){
        return [self.delegate sectionMargin:section];
    }
    return UIEdgeInsetsZero;
}

//Footer 高度
-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    if([self.delegate respondsToSelector:@selector(footerHeight:)]){
        return [self.delegate footerHeight:section];
    }
    return CGSizeZero;
}

//Header 高度
-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    
    if([self.delegate respondsToSelector:@selector(headerHeight:)]){
        return [self.delegate headerHeight:section];
    }
    return CGSizeZero;
}

//头部底部视图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if([kind isEqualToString:UICollectionElementKindSectionFooter]){
        if([self.delegate respondsToSelector:@selector(footerView:indexPath:)]){
            return [self.delegate footerView:collectionView indexPath:indexPath];
        }
    }else if([kind isEqualToString:UICollectionElementKindSectionHeader]){
        if([self.delegate respondsToSelector:@selector(headerView:indexPath:)]){
            return [self.delegate headerView:collectionView indexPath:indexPath];
        }
    }
    return nil;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if([self.delegate respondsToSelector:@selector(onItemClick:)]){
        [self.delegate onItemClick:indexPath];
    }
}
@end
